// pages/stopPayDetail/index.js
// var payData = require("../data/paydetail.js");
const app = getApp()
import { formatTime } from "../../utils/util.js";
Page({

  /**
   * 页面的初始数据
   */
  data: {
    imgurl: "https://apikb.zjkbtc.com/pic1.png",
    // ../../images/cs1.png
    item: {},
    showModal: false,
    orderNum: ''
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {

  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {
    var that = this,
      url = '';
    if (this.options.item) {
      url = app.globalData.basicUrl + 'user/userOrder/' + this.options.item
    } else {
      url = app.globalData.basicUrl + 'user/expense/' + this.options.exid
      // + wx.getStorageSync('userId')
    }
    wx.request({
      url: url,
      success: function (res) {
        console.log(res);
        res.data.data.orderAmount = res.data.data.orderAmount / 100
        res.data.data.amount = res.data.data.amount / 100
        that.data.orderNum = res.data.data.orderNum
        if (res.data.data.orderCreateTime) {
          var dateBegin = new Date(res.data.data.orderCreateTime.replace(/-/g, "/"));
          let dataDateEnd = res.data.data.orderCompleteTime;
          var dateEnd = dataDateEnd ? new Date(dataDateEnd.replace(/-/g, "/")) : null;
          var dateDiff = dataDateEnd ? (dateEnd.getTime() - dateBegin.getTime()) : (new Date().getTime() - dateBegin.getTime());
          if (dateDiff) {
            //时间差的毫秒数
            var dayDiff = Math.floor(dateDiff / (24 * 3600 * 1000)); //计算出相差天数
            var leave1 = dateDiff % (24 * 3600 * 1000) //计算天数后剩余的毫秒数
            var hours = Math.floor(leave1 / (3600 * 1000)) //计算出小时数
            //计算相差分钟数
            var leave2 = leave1 % (3600 * 1000) //计算小时数后剩余的毫秒数
            var minutes = Math.floor(leave2 / (60 * 1000)) //计算相差分钟数
            //计算相差秒数
            var leave3 = leave2 % (60 * 1000) //计算分钟数后剩余的毫秒数
            var seconds = Math.round(leave3 / 1000)
            console.log(" 相差 " + dayDiff + "天 " + hours + "小时 " + minutes + " 分钟" + seconds + " 秒")
            res.data.data.dataDiff = dayDiff + "天" + hours + "小时 " + minutes + "分钟"
          }else{
            res.data.data.dataDiff = null
          }
        }
        that.setData({
          item: res.data.data
        })
      }
    })
  },

  pay: function () {
    this.setData({
      showModal: true
    })
  },
  hideModal: function () {
    this.setData({
      showModal: false
    });
  },
  /**
   * 对话框取消按钮点击事件 本地支付
   */
  onCancel: function () {
    var that = this;
    app.onPayCancel(that, 'user/wxPay/localPay', {
      orderNum: that.data.orderNum
    })
  },
  /**
   * 对话框确认按钮点击事件  微信支付
   */
  onConfirm: function () {
    let that = this;
    app.onPayConfirm(that, 'user/wxPay/createNative', '&orderId=' + this.options.item)
  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})